package com.springboot.idcard.util;

import net.sourceforge.tess4j.ITesseract;
import net.sourceforge.tess4j.Tesseract;
import net.sourceforge.tess4j.TesseractException;

import java.io.File;

public class Tess4JUtil {
    private static ITesseract instance;
    static {
        instance = new Tesseract();
        instance.setDatapath("D:\\Program Files (x86)\\tessdata");//设置你的Tess4J下的tessdata目录
        instance.setLanguage("chi_sim");//指定需要识别的语种
        instance.setTessVariable("user_defined_dpi", "300");
    }

    public static void main(String[] args) {
        File image = new File("D:\\111.jpg");
        try {
            String res = instance.doOCR(image);
            System.out.println(res);
        } catch (TesseractException e) {
            e.printStackTrace();
        }
    }
}
